//
//  HBDateChooseViewController.m
//  HBLibary_Example
//
//  Created by Rambo on 2019/6/8.
//  Copyright © 2019 Rambo. All rights reserved.
//

#import "HBDateChooseViewController.h"
#import "HBDateChooseView.h"

@interface HBDateChooseViewController ()

@end

@implementation HBDateChooseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"时间选择器";
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"时间选择器" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
//    button.frame = CGRectMake(0, 0, 120, 40);
    [self.view addSubview:button];
//    button.center = self.view.center;
    button.translatesAutoresizingMaskIntoConstraints =  NO;
    NSLayoutConstraint *layoutCenterX = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    [self.view addConstraint:layoutCenterX];
    
    NSLayoutConstraint *layoutCenterY = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [self.view addConstraint:layoutCenterY];
//
    NSLayoutConstraint *layoutCenterH = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeHeight relatedBy:(NSLayoutRelationEqual) toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:40];
    [self.view addConstraint:layoutCenterH];

    NSLayoutConstraint *layoutCenterW = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeWidth relatedBy:(NSLayoutRelationEqual) toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:100];
    [self.view addConstraint:layoutCenterW];
}

- (void)buttonClick{
    
   HBDateChooseView *view = [HBDateChooseView showWithTitle:@"时间选择器" leftToolTitle:@"取消" rightToolTitle:@"确定" complete:^(UIDatePicker *datePicker) {
        NSLog(@"%@", datePicker.date);
    }];
    view.datePickerLineColor = [UIColor redColor];
    view.canTouchDismiss = YES;
}

@end
